<?php require_once(dirname(__FILE__) . '/../include/config.inc.php');
require_once "function.php";
/*
进度：
0 已经撤单
1 报修成功
2 客服已经联系
3 系统已经派单
4 工程师接单
5 维修完成
6 已经评价
*/

if (isset($uid)) {

    //有session 从数据库中读取用户名信息
    //$openid_str=$_SESSION['openid'];
    $sql = "SELECT u.*,g.groupname  as groupname FROM `#@__user` as u 
				   left join `#@__usergroup` as g  on u.level=g.id  
				   WHERE u.id='$uid' ";
    $row = $dosql->GetOne($sql);
    if (is_array($row) && isset($row['id'])) {
        // 返回用户 id
        $id = $row['id'];
        $_SESSION['id'] = $id;
        $userInfo = $row;
        $level = intval($row['level']);
        $isadmin = intval($row['isadmin']);
        $fee = intval($row['fee']);
    }
}

$timestamp=time();
if ($level < 5) {
    // 上月奖励
    $last_mouth_time1=strtotime(date('Y-m-01', strtotime('-1 month')));
    $last_mouth_time2=strtotime(date('Y-m-t', strtotime('-1 month')))+86400;
    $sql_order="SELECT `id`,`op`,`fee` FROM `#@__fee_log` WHERE `manageid`='$id' and op_time>$last_mouth_time1 and op_time<$last_mouth_time2  ";

    //获取所有的 记录合计
    $last_mouth_fee=0;
    $dosql->Execute($sql_order,7);
    while($order=$dosql->GetArray(7)){
        if($order['op']=='add'){
            $last_mouth_fee+=$order['fee'];
        }elseif($order['op']=='move'){
            $last_mouth_fee-=$order['fee'];
        }
    }

    // 当月月奖励
    $this_mouth_time1=strtotime(date('Y-m-01'));
    $sql_order2="SELECT `id`,`op`,`fee` FROM `#@__fee_log` WHERE `manageid`='$id' and op_time>$this_mouth_time1  ";

    //获取所有的 记录合计
    $this_mouth_fee=0;
    $dosql->Execute($sql_order2,8);
    while($order2=$dosql->GetArray(8)){
        if($order2['op']=='add'){
            $this_mouth_fee+=$order2['fee'];
        }elseif($order2['op']=='move'){
            $this_mouth_fee-=$order2['fee'];
        }
    }

    // 当日 奖励
    $day_time1=strtotime(date('Y-m-d'));
    $sql_order3="SELECT `id`,`op`,`fee` FROM `#@__fee_log` WHERE `manageid`='$id' and op_time>$day_time1  ";

    //获取所有的 记录合计
    $day_fee=0;
    $dosql->Execute($sql_order3,9);
    while($order33=$dosql->GetArray(9)){
        if($order33['op']=='add'){
            $day_fee+=$order33['fee'];
        }elseif($order2['op']=='move'){
            $day_fee-=$order33['fee'];
        }
    }

    $dosql->Execute("SELECT `id` FROM `#@__order` WHERE `jindu`=6  AND  FIND_IN_SET('$uid',manageid)   AND  is_delete=0   ", 12);
    $my_count2 = $dosql->GetTotalRow(12); //已评价

    $dosql->Execute("SELECT `id` FROM `#@__order` WHERE `jindu`=3   AND  FIND_IN_SET('$uid',manageid)  and  is_delete=0    ", 14);
    $my_count4 = $dosql->GetTotalRow(14); //维修中

    $dosql->Execute("SELECT `id` FROM `#@__order` WHERE `jindu`=4  AND  FIND_IN_SET('$uid',manageid)  and  is_delete=0    ", 15);
    $my_count5 = $dosql->GetTotalRow(15); //报修完成

    $dosql->Execute("SELECT `id` FROM `#@__order` WHERE `jindu`=5  AND  FIND_IN_SET('$uid',manageid)   and is_delete=0    ", 16);
    $my_count6 = $dosql->GetTotalRow(16); //报修完成

}
?>
    <!DOCTYPE html>
    <html>
    <head>
        <title>我的工作台-<?php echo $cfg_webname; ?></title>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="description" content="<?php echo $cfg_webname; ?>">
        <link rel="stylesheet" href="lib/weui.min.css">
        <link rel="stylesheet" href="css/jquery-weui.css">
        <link rel="stylesheet" href="css/font-awesome.min.css">
        <link rel="stylesheet" href="css/demos.css?v=20201211.1756">
    </head>

<body ontouchstart>
<div class="top">
    <div class="user_top user_project">
        <i>
            <?php
            if (intval($row['level']) > 1) {
                echo '<a href="manage.php">' . $userInfo['groupname'] . '</a>';
            } else {
                echo $userInfo['groupname'];
            } ?>
            UID:<?php echo $id; ?>
        </i>
        <div class="user_top_conn"><img src="<?php echo $userInfo['headimgurl'] ?>"/>
            <p><?php echo $userInfo['truename'] ?></p>
        </div>
    </div>
</div>

<div class="main" style="margin-top: 0">
    <div class="aui-palace aui-palace-one">
        <a href="javascript:;" class="aui-palace-grid">
            <div class="aui-palace-grid-text">
                <h4><?php echo $fee;?></h4>
                <h5>总奖励</h5>
            </div>
        </a>
        <a href="javascript:;" class="aui-palace-grid">
            <div class="aui-palace-grid-text">
                <h4><?php  echo $last_mouth_fee ?></h4>
                <h5>上月</h5>
            </div>
        </a>
        <a href="javascript:;" class="aui-palace-grid">
            <div class="aui-palace-grid-text">
                <h4><?php  echo $this_mouth_fee ?></h4>
                <h5>本月</h5>
            </div>
        </a>
        <a href="javascript:;" class="aui-palace-grid">
            <div class="aui-palace-grid-text">
                <h4 class="no-border"><?php  echo $day_fee ?></h4>
                <h5 class="no-border" style="color: #0BB20C">当日</h5>
            </div>
        </a>
    </div>
</div>

<div class="main">
    <!-- 工单状态 -->
    <div class="Order">
        <dl>
            <a href="myorder.php">
                <dt><strong><i class="fa fa-server" aria-hidden="true"></i>我的任务</strong><span>查看我的全部任务</span></dt>
            </a>
        </dl>
        <ul>
            <li>
                <a href="myorder.php?jindu=3"><em class="ordem1"><i><?php echo $my_count4 ?></i></em><span>待接单</span></a>
            </li>
            <li>
                <a href="myorder.php?jindu=4"><em class="ordem4"><i><?php echo $my_count5 ?></i></em><span>未完成</span></a>
            </li>
            <li><a href="myorder.php?jindu=5"><em class="Icon1"><i><?php echo $my_count6 ?></i></em><span>待评价</span></a>
            </li>
            <li><a href="myorder.php?jindu=6"><em class="Icon1"><i><?php echo $my_count2 ?></i></em><span>已评价</span></a>
            </li>
            <?php
            if($isadmin==1){
                echo '<li><a href="pm.php"><em class="Icon_yuangong"></em><span>员工</span></a></li>';
            }
            ?>

        </ul>
    </div>
</div>




<div class="clear"></div>
<script src="lib/jquery-2.1.4.js"></script>
<script src="lib/fastclick.js"></script>
<script>
    $(function () {
        FastClick.attach(document.body);
    });
</script>
<script src="js/jquery-weui.js"></script>
<script src="js/city-picker.js"></script>

<div class="sub_btn"></div>
<?php require_once('footer.php'); ?>